home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 10 code / GWorld Drawing / GWorld Routines / DemoRoutines.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-08  |  16.1 KB  |  609 lines  |  [TEXT/KAHL]

  1. #include "DemoRoutines.h"
  2.  
  3. OSErr TestGetSetPixel(PicHandle pict)
  4. {
  5. GDHandle    oldGD;
  6. GWorldPtr    oldGW;
  7. GWorldPtr    myOffGWorld;
  8. PixMapHandle myPixMapHandle;
  9.  
  10. short        x,y;
  11. Rect        bounds;
  12. Rect        mybounds;
  13. PixMap        *myPixMapPtr;
  14. long        startTicks;
  15. Str255        theString;
  16. RGBColor    myRGB;
  17.  
  18.     bounds = (*pict)->picFrame;
  19.     mybounds = bounds;
  20.     OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
  21.     DrawPicture( pict, &mybounds );
  22.     OffsetRect( &bounds, 100, 100 );
  23.  
  24.     if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
  25.     {
  26.         GetGWorld(&oldGW,&oldGD);
  27.         SetGWorld(myOffGWorld,nil);
  28.  
  29.         EraseRect( &bounds );        /* clear the GWorld */
  30.         
  31.         myPixMapHandle = GetGWorldPixMap( myOffGWorld );    /* 7.0 only */
  32.  
  33.         LockPixels( myPixMapHandle );
  34.         DrawPicture( pict, &bounds );
  35.  
  36.         myPixMapHandle = GetGWorldPixMap( myOffGWorld );
  37.  
  38.         startTicks = *(long*)0x16a;
  39.         for( y = bounds.top; y< bounds.bottom; y++ )
  40.         {
  41.             for( x = bounds.left; x < bounds.right; x++ )
  42.             {
  43.                 GetCPixel( x, y, &myRGB );
  44.                 myRGB.red ^=0xFFFF;            /* invert the red and green channels */
  45.                 myRGB.green ^=0xFFFF;
  46.                 SetCPixel( x, y, &myRGB );
  47.             }
  48.         }
  49.  
  50.         SetGWorld(oldGW,oldGD);    
  51.  
  52.         TextMode( srcCopy );
  53.         MoveTo( 30,30 );
  54.         {    long ticks = *(long*)0x16a - startTicks;
  55.         NumToString( ticks, theString );    /* Ticks */
  56.         DrawString( theString );
  57.         }
  58.         myPixMapHandle = GetGWorldPixMap( myOffGWorld );    /* 7.0 only */
  59.         CopyBits( (BitMap*)*myPixMapHandle, (BitMap*)&thePort->portBits, &bounds, &bounds, srcCopy, 0 );
  60.         DisposeGWorld( myOffGWorld );
  61.     }
  62.     else
  63.         return memFullErr;
  64.     return noErr;
  65. }
  66.  
  67. OSErr TestBetterGetSetPixel(PicHandle pict)
  68. {
  69. GDHandle    oldGD;
  70. GWorldPtr    oldGW;
  71. GWorldPtr    myOffGWorld;
  72. PixMapHandle myPixMapHandle;
  73.  
  74. short        x,y;
  75. long        myPixel;
  76. Rect        bounds;
  77. Rect        mybounds;
  78. long        startTicks;
  79. Str255        theString;
  80.  
  81.     bounds = (*pict)->picFrame;
  82.     mybounds = bounds;
  83.     OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
  84.     DrawPicture( pict, &mybounds );
  85.     OffsetRect( &bounds, 100, 100 );
  86.  
  87.     if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
  88.     {
  89.         GetGWorld(&oldGW,&oldGD);
  90.         SetGWorld(myOffGWorld,nil);
  91.  
  92.         EraseRect( &bounds );        /* clear the GWorld */
  93.         
  94.         myPixMapHandle = GetGWorldPixMap( myOffGWorld );    /* 7.0 only */
  95.  
  96.         LockPixels( myPixMapHandle );
  97.         DrawPicture( pict, &bounds );
  98.         UnlockPixels( myPixMapHandle );
  99.  
  100.         startTicks = *(long*)0x16a;
  101.         LockPixels( myPixMapHandle );
  102.         for( y = bounds.top; y< bounds.bottom; y++ )
  103.         {
  104.             for( x = bounds.left; x < bounds.right; x++ )
  105.             {
  106.                 myPixel = GWGet32PixelC( myOffGWorld,  x,  y );    
  107.                 myPixel ^= 0x00FFFF00;                /* invert the red and green channels */
  108.                 GWSet32PixelC( myOffGWorld, x, y, myPixel );
  109.             }
  110.         }
  111.  
  112.         SetGWorld(oldGW,oldGD);    
  113.  
  114.         TextMode( srcCopy );
  115.         MoveTo( 30,30 );
  116.         {    long ticks = *(long*)0x16a - startTicks;
  117.         NumToString( ticks, theString );    /* Ticks */
  118.         DrawString( theString );
  119.         }
  120.  
  121.         myPixMapHandle = GetGWorldPixMap( myOffGWorld );    /* 7.0 only */
  122.         CopyBits( (BitMap*)*myPixMapHandle, (BitMap*)&thePort->portBits, &bounds, &bounds, srcCopy, 0 );
  123.         DisposeGWorld( myOffGWorld );
  124.     }
  125.     else
  126.         return memFullErr;
  127.     return noErr;
  128. }
  129.  
  130.  
  131.  
  132. OSErr
  133. TestFastGetSetPixel(PicHandle pict)
  134. {
  135. GDHandle    oldGD;
  136. GWorldPtr    oldGW;
  137. GWorldPtr    myOffGWorld;
  138. PixMapHandle myPixMapHandle;
  139.  
  140. short        x,y;
  141. long        myPixel;
  142. Rect        bounds;
  143. Rect        mybounds;
  144. long        *srcBaseAddr;
  145. char        mmuMode;
  146. PixMap        *myPixMapPtr;
  147. long        startTicks;
  148. Str255        theString;
  149.  
  150.     bounds = (*pict)->picFrame;
  151.     mybounds = bounds;
  152.     OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
  153.     DrawPicture( pict, &mybounds );
  154.     OffsetRect( &bounds, 100, 100 );
  155.  
  156.     if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
  157.     {
  158.         GetGWorld(&oldGW,&oldGD);
  159.         SetGWorld(myOffGWorld,nil);
  160.  
  161.         EraseRect( &bounds );        /* clear the GWorld */
  162.         
  163.         myPixMapHandle = GetGWorldPixMap( myOffGWorld );    /* 7.0 only */
  164.  
  165.         LockPixels( myPixMapHandle );
  166.         DrawPicture( pict, &bounds );
  167.         UnlockPixels( myPixMapHandle );
  168.  
  169.         srcBaseAddr = (long *) GetPixBaseAddr ( myPixMapHandle );    /* get 32-bit base address of the pixmap */
  170.         myPixMapPtr = *myPixMapHandle;
  171.  
  172. /*
  173. ** WARNING:  The PixMapHandle is dereferenced throughout these next loops.
  174. ** The code makes sure memory will not move.  In particular, it is important that 
  175. ** the segment containing the FastGWGet32Pixel and FastGWSet32Pixel routines
  176. ** is already loaded, or is in the same segment as the caller.  Otherwise memory might
  177. ** move when the segment is loaded.  A trick to make sure the segment is loaded is to call
  178. ** a routine in the same segment (or these routines themselves) before making assumptions
  179. ** about memory not moving.
  180. */
  181.         /* Make it 32-bit clean */
  182.         LockPixels(myPixMapHandle);
  183.         myPixMapPtr = (PixMap *)StripAddress( (Ptr)myPixMapPtr );                /* Make it 32-bit clean */
  184.         
  185.         mmuMode = true32b;
  186.         SwapMMUMode ( &mmuMode );                            /* set the MMU to 32-bit mode */
  187.         startTicks = *(long*)0x16a;
  188.         for( y = bounds.top; y< bounds.bottom; y++ )
  189.         {
  190.             for( x = bounds.left; x < bounds.right; x++ )
  191.             {
  192.                 myPixel = FastGWGet32Pixel( myPixMapPtr, srcBaseAddr,  x,  y );    
  193.                 myPixel ^= 0x00FFFF00;                /* invert the red and green channels */
  194.                 FastGWSet32Pixel( myPixMapPtr, srcBaseAddr, x, y, myPixel );
  195.             }
  196.         }
  197.         SwapMMUMode ( &mmuMode );                        /* set it back */
  198.  
  199.         SetGWorld(oldGW,oldGD);    
  200.  
  201.         TextMode( srcCopy );
  202.         MoveTo( 30,30 );
  203.         NumToString( *(long*)0x16a - startTicks, theString );    /* Ticks */
  204.         DrawString( theString );
  205.  
  206.         myPixMapHandle = GetGWorldPixMap( myOffGWorld );    /* 7.0 only */
  207.         CopyBits( (BitMap*)*myPixMapHandle, (BitMap*)&thePort->portBits, &bounds, &bounds, srcCopy, 0 );
  208.         DisposeGWorld( myOffGWorld );
  209.     }
  210.     else
  211.         return memFullErr;
  212.     return noErr;
  213. }
  214.  
  215.  
  216. OSErr
  217. TestRedGreenInvert(PicHandle pict)
  218. {
  219. GDHandle    oldGD;
  220. GWorldPtr    oldGW;
  221. GWorldPtr    myOffGWorld;
  222. PixMapHandle myPixMapHandle;
  223.  
  224. short        x,y;
  225. long        myPixel;
  226. Rect        bounds;
  227. Rect        mybounds;
  228. long        srcBaseAddr;
  229. PixMap        *myPixMapPtr;
  230. long        startTicks;
  231. Str255        theString;
  232.  
  233.     bounds = (*pict)->picFrame;
  234.     mybounds = bounds;
  235.     OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
  236.     DrawPicture( pict, &mybounds );
  237.     OffsetRect( &bounds, 100, 100 );
  238.  
  239.     if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
  240.     {
  241.         GetGWorld(&oldGW,&oldGD);
  242.         SetGWorld(myOffGWorld,nil);
  243.  
  244.         EraseRect( &bounds );        /* clear the GWorld */
  245.         
  246.         myPixMapHandle = GetGWorldPixMap( myOffGWorld );    /* 7.0 only */
  247.  
  248.         LockPixels( myPixMapHandle );
  249.         DrawPicture( pict, &bounds );
  250.         UnlockPixels( myPixMapHandle );
  251.  
  252.  
  253.         startTicks = *(long*)0x16a;
  254.  
  255.         RedGreenInvert( myOffGWorld );
  256.         
  257.         SetGWorld(oldGW,oldGD);    
  258.         TextMode( srcCopy );
  259.         MoveTo( 30,30 );
  260.         NumToString( *(long*)0x16a - startTicks, theString );    /* Ticks */
  261.         DrawString( theString );
  262.         CopyBits( (BitMap*)*myPixMapHandle, (BitMap*)&thePort->portBits, &bounds, &bounds, srcCopy, 0 );
  263.         DisposeGWorld( myOffGWorld );
  264.     }
  265.     else
  266.         return memFullErr;
  267.     return noErr;
  268. }
  269.  
  270. OSErr
  271. TestCalculateDelta(PicHandle pict)
  272. {
  273. OSErr        err = memFullErr;
  274. GDHandle    oldGD;
  275. GWorldPtr    oldGW;
  276. GWorldPtr    myOffGWorld;
  277. GWorldPtr    myOffGWorld1;
  278. PixMapHandle myPixMapHandle;
  279. PixMapHandle myPixMapHandle1;
  280. CTabHandle    myGrayCTable;
  281. Rect            bounds, mybounds;
  282.  
  283.     bounds = (*pict)->picFrame;
  284.     mybounds = bounds;
  285.     OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
  286. /* Draw it to the screen */
  287.     DrawPicture( pict, &mybounds );
  288.     OffsetRect( &bounds, 100, 100 );
  289.  
  290.     if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
  291.     {
  292.         GetGWorld(&oldGW,&oldGD);
  293.         SetGWorld(myOffGWorld,nil);
  294.         EraseRect( &bounds );        /* clear the GWorld */
  295.         myPixMapHandle = GetGWorldPixMap( myOffGWorld );
  296.         LockPixels( myPixMapHandle );
  297. /* Draw it to the GWorld */
  298.         DrawPicture( pict, &bounds );
  299.         UnlockPixels( myPixMapHandle );
  300.         SetGWorld(oldGW,oldGD);                        /* Copy to window */
  301.         myGrayCTable = GetCTable( 40 );        /* Defaullt 256 gray table */
  302.         if( !NewGWorld( &myOffGWorld1, 8, &bounds, myGrayCTable, 0, 0 ) )
  303.         {
  304.             CalculateDeltas( myOffGWorld, myOffGWorld1 );
  305.             myPixMapHandle1 = GetGWorldPixMap( myOffGWorld1 );    /* 7.0 only */
  306.             CopyBits( (BitMap *)*myPixMapHandle1, (BitMap *)&thePort->portBits, &bounds, &bounds,  srcCopy, 0 );
  307.             DisposeGWorld( myOffGWorld1 );
  308.             err = noErr;        
  309.         }
  310.         DisposeGWorld( myOffGWorld );
  311.     }
  312.  
  313.     return err;
  314. }
  315.  
  316. OSErr
  317. TestCalculateDeltaFast(PicHandle pict)
  318. {
  319. OSErr        err = memFullErr;
  320. GDHandle    oldGD;
  321. GWorldPtr    oldGW;
  322. GWorldPtr    myOffGWorld;
  323. GWorldPtr    myOffGWorld1;
  324. PixMapHandle myPixMapHandle;
  325. PixMapHandle myPixMapHandle1;
  326. CTabHandle    myGrayCTable;
  327. Rect            bounds, mybounds;
  328.  
  329.     bounds = (*pict)->picFrame;
  330.     mybounds = bounds;
  331.     OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
  332. /* Draw it to the screen */
  333.     DrawPicture( pict, &mybounds );
  334.     OffsetRect( &bounds, 100, 100 );
  335.  
  336.     if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
  337.     {
  338.         GetGWorld(&oldGW,&oldGD);
  339.         SetGWorld(myOffGWorld,nil);
  340.         EraseRect( &bounds );        /* clear the GWorld */        
  341.         myPixMapHandle = GetGWorldPixMap( myOffGWorld );
  342.         LockPixels( myPixMapHandle );
  343. /* Draw it to the GWorld */
  344.         DrawPicture( pict, &bounds );
  345.         UnlockPixels( myPixMapHandle );
  346.         SetGWorld(oldGW,oldGD);                        /* Copy to window */
  347.         myGrayCTable = GetCTable( 40 );        /* Defaullt 256 gray table */
  348.         if( !NewGWorld( &myOffGWorld1, 8, &bounds, myGrayCTable, 0, 0 ) )
  349.         {
  350.             FastCalculateDeltas( myOffGWorld, myOffGWorld1 );
  351.             myPixMapHandle1 = GetGWorldPixMap( myOffGWorld1 );    /* 7.0 only */
  352.             CopyBits( (BitMap *)*myPixMapHandle1, (BitMap *)&thePort->portBits, &bounds, &bounds,  srcCopy, 0 );
  353.             DisposeGWorld( myOffGWorld1 );
  354.             err = noErr;        
  355.         }
  356.         DisposeGWorld( myOffGWorld );
  357.     }
  358. }
  359.  
  360.  
  361. OSErr TestBoxScale(PicHandle pict)
  362. {
  363.     GWorldPtr srcWorld;
  364.     Rect srcBounds;
  365.     Point srcCenter, screenCenter;
  366.     short err;
  367.     
  368.     srcBounds = (*pict)->picFrame;
  369.     OffsetRect( &srcBounds, -srcBounds.left, -srcBounds.top);
  370.     /* Draw it to the screen */
  371.     DrawPicture( pict, &srcBounds );
  372.  
  373.     srcWorld = PictToGWorld( pict, &srcBounds );
  374.     if(srcWorld == nil)
  375.         return memFullErr;
  376.         
  377.     srcBounds = srcWorld->portRect;
  378.     SetPt(&srcCenter, srcBounds.right + srcBounds.left >> 1, 
  379.             srcBounds.bottom + srcBounds.top >> 1);
  380.     SetPt(&screenCenter, thePort->portRect.right - thePort->portRect.left >> 1,
  381.         thePort->portRect.bottom - thePort->portRect.top >> 1);
  382.  
  383.     {    
  384.         mapping map;
  385.         GWorldPtr dstWorld, maskWorld;
  386.         Rect dstBounds, screenBounds, maskBounds;
  387.         PixMapHandle dstPixels, maskPixels;
  388.     
  389.         SetIdentityMapping(&map);
  390.         ScaleMapping(&map, ff(1) + 0x8000, ff(1) + 0x8000, ff(srcCenter.h), ff(srcCenter.v));
  391.  
  392.         dstWorld = MapGWorldBox(srcWorld, &map, &maskWorld);
  393.         dstPixels = GetGWorldPixMap( dstWorld );
  394.         maskPixels = GetGWorldPixMap( maskWorld );
  395.         dstBounds = dstWorld->portRect;
  396.         maskBounds = maskWorld->portRect;
  397.  
  398.         screenBounds = dstBounds;
  399.         CenterRect(&screenBounds, screenCenter.h, screenCenter.v);
  400.  
  401.         LockPixels(dstPixels);
  402.         LockPixels(maskPixels);
  403.         CopyDeepMask((BitMap*)*dstPixels, (BitMap*)*maskPixels, &thePort->portBits,
  404.                     &dstBounds, &maskBounds, &screenBounds, srcCopy + ditherCopy, 0);
  405.         DisposeGWorld( maskWorld );
  406.         DisposeGWorld( dstWorld );
  407.     }
  408.     DisposeGWorld( srcWorld );
  409.     return noErr;
  410. }
  411.  
  412. OSErr TestTentScale(PicHandle pict)
  413. {
  414.     GWorldPtr srcWorld;
  415.     Rect srcBounds;
  416.     Point srcCenter, screenCenter;
  417.     short err;
  418.     
  419.     srcBounds = (*pict)->picFrame;
  420.     OffsetRect( &srcBounds, -srcBounds.left, -srcBounds.top);
  421. /* Draw it to the screen */
  422.     DrawPicture( pict, &srcBounds );
  423.  
  424.     srcWorld = PictToGWorld( pict, &srcBounds );
  425.     if(srcWorld == nil)
  426.         return memFullErr;
  427.         
  428.     srcBounds = srcWorld->portRect;
  429.     SetPt(&srcCenter, srcBounds.right + srcBounds.left >> 1, 
  430.             srcBounds.bottom + srcBounds.top >> 1);
  431.     SetPt(&screenCenter, thePort->portRect.right - thePort->portRect.left >> 1,
  432.         thePort->portRect.bottom - thePort->portRect.top >> 1);
  433.  
  434.     {    
  435.         mapping map;
  436.         GWorldPtr dstWorld, maskWorld;
  437.         Rect dstBounds, screenBounds, maskBounds;
  438.         PixMapHandle dstPixels, maskPixels;
  439.     
  440.         SetIdentityMapping(&map);
  441.         ScaleMapping(&map, ff(1) + 0x8000, ff(1) + 0x8000, ff(srcCenter.h), ff(srcCenter.v));
  442.  
  443.         dstWorld = MapGWorldTent(srcWorld, &map, &maskWorld);
  444.         dstPixels = GetGWorldPixMap( dstWorld );
  445.         maskPixels = GetGWorldPixMap( maskWorld );
  446.         dstBounds = dstWorld->portRect;
  447.         maskBounds = maskWorld->portRect;
  448.  
  449.         screenBounds = dstBounds;
  450.         CenterRect(&screenBounds, screenCenter.h, screenCenter.v);
  451.  
  452.         LockPixels(dstPixels);
  453.         LockPixels(maskPixels);
  454.         CopyDeepMask((BitMap*)*dstPixels, (BitMap*)*maskPixels, &thePort->portBits,
  455.                     &dstBounds, &maskBounds, &screenBounds, srcCopy + ditherCopy, 0);
  456.         DisposeGWorld( maskWorld );
  457.         DisposeGWorld( dstWorld );
  458.     }
  459.     DisposeGWorld( srcWorld );
  460.     return noErr;
  461. }
  462.  
  463. OSErr TestRotate(PicHandle pict)
  464. {
  465.     GWorldPtr srcWorld;
  466.     Rect srcBounds;
  467.     Point srcCenter, screenCenter;
  468.     short err;
  469.     
  470.     srcBounds = (*pict)->picFrame;
  471.     OffsetRect( &srcBounds, -srcBounds.left, -srcBounds.top);
  472. /* Draw it to the screen */
  473.     DrawPicture( pict, &srcBounds );
  474.  
  475.     srcWorld = PictToGWorld( pict, &srcBounds );
  476.     if(srcWorld == nil)
  477.         return memFullErr;
  478.         
  479.     srcBounds = srcWorld->portRect;
  480.     SetPt(&srcCenter, srcBounds.right + srcBounds.left >> 1, 
  481.             srcBounds.bottom + srcBounds.top >> 1);
  482.     SetPt(&screenCenter, thePort->portRect.right - thePort->portRect.left >> 1,
  483.         thePort->portRect.bottom - thePort->portRect.top >> 1);
  484.  
  485.     {    
  486.         mapping map;
  487.         GWorldPtr dstWorld, maskWorld;
  488.         Rect dstBounds, screenBounds, maskBounds;
  489.         PixMapHandle dstPixels, maskPixels;
  490.     
  491.         SetIdentityMapping(&map);
  492.         RotateMapping(&map, ff(35), ff(srcCenter.h), ff(srcCenter.v));
  493.  
  494.         dstWorld = MapGWorldBox(srcWorld, &map, &maskWorld);
  495.         dstPixels = GetGWorldPixMap( dstWorld );
  496.         maskPixels = GetGWorldPixMap( maskWorld );
  497.         dstBounds = dstWorld->portRect;
  498.         maskBounds = maskWorld->portRect;
  499.  
  500.         screenBounds = dstBounds;
  501.         CenterRect(&screenBounds, screenCenter.h, screenCenter.v);
  502.  
  503.         LockPixels(dstPixels);
  504.         LockPixels(maskPixels);
  505.         CopyDeepMask((BitMap*)*dstPixels, (BitMap*)*maskPixels, &thePort->portBits,
  506.                     &dstBounds, &maskBounds, &screenBounds, srcCopy + ditherCopy, 0);
  507.         DisposeGWorld( maskWorld );
  508.         DisposeGWorld( dstWorld );
  509.     }
  510.     DisposeGWorld( srcWorld );
  511.     return noErr;
  512. }
  513.  
  514. OSErr TestWarp(PicHandle pict)
  515. {
  516.     GWorldPtr srcWorld;
  517.     Rect srcBounds;
  518.     Point srcCenter, screenCenter;
  519.     short err;
  520.     
  521.     srcBounds = (*pict)->picFrame;
  522.     OffsetRect( &srcBounds, -srcBounds.left, -srcBounds.top);
  523. /* Draw it to the screen */
  524.     DrawPicture( pict, &srcBounds );
  525.  
  526.     srcWorld = PictToGWorld( pict, &srcBounds );
  527.     if(srcWorld == nil)
  528.         return memFullErr;
  529.         
  530.     srcBounds = srcWorld->portRect;
  531.     SetPt(&srcCenter, srcBounds.right + srcBounds.left >> 1, 
  532.             srcBounds.bottom + srcBounds.top >> 1);
  533.     SetPt(&screenCenter, thePort->portRect.right - thePort->portRect.left >> 1,
  534.         thePort->portRect.bottom - thePort->portRect.top >> 1);
  535.  
  536.     {    
  537.         mapping map;
  538.         GWorldPtr dstWorld, maskWorld;
  539.         Rect dstBounds, screenBounds, maskBounds;
  540.         PixMapHandle dstPixels, maskPixels;
  541.     
  542.         SetIdentityMapping(&map);
  543.  
  544.         dstWorld = FancyMapGWorld(srcWorld, &map, &maskWorld);
  545.         dstPixels = GetGWorldPixMap( dstWorld );
  546.         maskPixels = GetGWorldPixMap( maskWorld );
  547.         dstBounds = dstWorld->portRect;
  548.         maskBounds = maskWorld->portRect;
  549.  
  550.         screenBounds = dstBounds;
  551.         CenterRect(&screenBounds, screenCenter.h, screenCenter.v);
  552.  
  553.         LockPixels(dstPixels);
  554.         LockPixels(maskPixels);
  555.         CopyDeepMask((BitMap*)*dstPixels, (BitMap*)*maskPixels, &thePort->portBits,
  556.                     &dstBounds, &maskBounds, &screenBounds, srcCopy + ditherCopy, 0);
  557.         DisposeGWorld( maskWorld );
  558.         DisposeGWorld( dstWorld );
  559.     }
  560.     DisposeGWorld( srcWorld );
  561.     return noErr;
  562. }
  563.  
  564. OSErr TestRectangleEffect(PicHandle pict)
  565. {
  566. GDHandle    oldGD;
  567. GWorldPtr    oldGW;
  568. GWorldPtr    myOffGWorld;
  569. GWorldPtr    myOffGWorld1;
  570. PixMapHandle myPixMapHandle;
  571. PixMapHandle myPixMapHandle1;
  572. CTabHandle    myGrayCTable;
  573. Rect            bounds, mybounds, blastRect;
  574.  
  575.     bounds = (*pict)->picFrame;
  576.     mybounds = bounds;
  577.     OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
  578. /* Draw it to the screen */
  579.     DrawPicture( pict, &mybounds );
  580.     OffsetRect( &bounds, 100, 100 );
  581.  
  582.     if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
  583.     {
  584.         blastRect.left = 0;
  585.         blastRect.top = 0;
  586.         GetGWorld(&oldGW,&oldGD);
  587.         myPixMapHandle = GetGWorldPixMap( myOffGWorld );
  588.  
  589.         SetGWorld(myOffGWorld,nil);
  590.         LockPixels( myPixMapHandle );
  591.         EraseRect( &bounds );        /* clear the GWorld */        
  592.         
  593.         /* Draw it to the GWorld */
  594.         DrawPicture( pict, &bounds );
  595.         UnlockPixels( myPixMapHandle );
  596.         SetGWorld(oldGW,oldGD);                        
  597.         
  598.         blastRect.right = 10;
  599.         blastRect.bottom = 10;
  600.         ImageBlastRect( &blastRect, myOffGWorld );
  601.         CopyBits( (BitMap *)*myPixMapHandle, (BitMap *)&thePort->portBits, 
  602.             &bounds, &bounds,  srcCopy + ditherCopy, 0 );
  603.         DisposeGWorld( myOffGWorld );
  604.     }
  605.     else
  606.         return memFullErr;
  607.     return noErr;
  608. }
  609.